package lc.双指针;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/24
 */
public class 剑指Offer57_和为s的两个数字 {

    public int[] twoSum(int[] nums, int target) {

        int l = 0;
        int r = nums.length - 1;
        while (l < r) {

            if (nums[l] + nums[r] == target) {
                return new int[]{nums[l],nums[r]};
            }
            if (nums[l] + nums[r] > target) {
                r--;
            }
            if (nums[l] + nums[r] < target) {
                l++;
            }
        }
        return new int[0];

    }
}
